$(function(){

    //问题解决
    var problems ={
    };

    /**
     * 初始化帮助类信息
     * **/
    problems.init = function(){
        $.ajax({
            async: false,
            url: '/help/findHelpList',
            success: function (result) {
                if (result && result.code == 200) {
                    if (result.data != '') {
                        var typePro =$('.problem-type');
                        var html ='';
                        $.each( result.data ,function(index ,obj ){
                            if( index == 0 ){
                                html +='<li helpId="'+obj.helpId+'" class="selPro">'+obj.helpName+'<span>&nbsp; ></span></li>';
                                problems.initSecond(obj.helpId);
                            }else{
                                html +='<li helpId="'+obj.helpId+'">'+obj.helpName+'</li>';
                            }
                        });
                        typePro.empty().append(html);
                        //绑定事件
                        typePro.find("li").on('click',function(){
                            var helpId = $(this).attr('helpId');//获取分类ID
                            typePro.find("li").find("span").remove();
                            typePro.find("li").removeClass("selPro");
                            $(this).html($(this).text()+'<span>&nbsp; ></span>');
                            $(this).addClass("selPro");
                            problems.initSecond(helpId);
                        });
                    }
                }
            },
            error: function () {
                layer.alert('服务器出错啦！', {icon: 2, title: '错误'});
            }
        });
    }

    /**
     * 获取分类下帮助信息
     * **/
    problems.initSecond = function(helpId){
        $.ajax({
            async: false,
            url: '/assistInfo/findAssistListById?helpId='+helpId,
            success: function (result) {
                if (result && result.code == 200) {
                    if (result.data != '') {
                        var typePro =$('.problem-list');
                        var html ='';
                        $.each( result.data ,function(index ,obj ){
                            html +='<li assistId="'+obj.assistId+'"><a href="/web/problemsDetail?id='+obj.assistId+'" title="'+obj.assistTitle+'">'+obj.assistTitle+'</a></li>';
                        });
                        typePro.empty().append(html);
                    }else{
                        $('.problem-list').empty().append('<span>没有相关问题!</span>');
                    }
                }
            },
            error: function () {
                layer.alert('服务器出错啦！', {icon: 2, title: '错误'});
            }
        });
    }




    //初始化
    problems.init();
    header.selLiCss("hz");
    //面包屑名称
    $("#menu-ico span").html("•&nbsp;&nbsp;客户服务&nbsp;&nbsp;•&nbsp;&nbsp;常见问题解答");
});